home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Interactive Reference Guide / C-C++ Interactive Reference Guide.iso / c_ref / csource4 / 223_01 / cseek.c < prev    next >
Text File  |  1979-12-31  |  2KB  |  67 lines

  1. #include stdio.h
  2.  
  3. /*
  4. ** cseek(fd,offset,base)    by F.A.Scacchitti    3/22/84
  5. **
  6. ** Position fd to the 128-byte record indicated by
  7. ** "offset" relative to the point indicated by "base."
  8. ** 
  9. **     BASE     OFFSET-RELATIVE-TO
  10. **       0      first record
  11. **       1      current record
  12. **       2      end of file (last record + 1)
  13. **
  14. ** Returns NULL on success, else EOF.
  15. */
  16.  
  17. extern char zzmxsc;
  18.  
  19. static char zzzext, zzzrec;
  20. static char *fcbdata;
  21. static int tempofs, unused;
  22.  
  23. cseek(fd, offset, base) int fd, offset, base; {
  24.  
  25.   fcbdata = fd;
  26.   switch (base) {
  27.     case 0:  getval(offset);
  28.              break;
  29.     case 1:  tempofs = gettof(fcbdata);
  30.              if(tempofs >= 8) tempofs -= (8 - zzmxsc);
  31.              getval(tempofs + offset);
  32.              break;
  33.     case 2:  while(bdos(20, fd) == NULL);
  34.              tempofs = gettof(fcbdata);
  35.              getval(tempofs - offset);
  36.              break;
  37.     default: return (EOF);
  38.     }
  39.   
  40.    fcbdata[12] = zzzext;   fcbdata[32] = zzzrec;
  41.  
  42.    if(fcbdata[33] != 1){
  43.        fcbdata[33] = 0;
  44.        if(cpmio(20,fd) == EOF);
  45.           if(zzmxsc == 8) return(EOF);
  46.           unused = 1024 - (zzmxsc * 128);
  47.    }else{
  48.       unused = 0;
  49.    }
  50.    *(fd + 38) = unused;
  51.    *(fd + 36) = fd + 42;
  52.    return (NULL);
  53. }
  54.  
  55. getval(offset) int offset;{
  56.   zzzext = offset / 80;
  57.   zzzrec = offset % 80;
  58. }
  59.  
  60. gettof(fcbdata) char *fcbdata; {
  61. int tempofs;
  62.  
  63.    return(fcbdata[12] * 80 + fcbdata[32]);
  64.  
  65. }
  66.  
  67.